<?php
namespace common\bonus;
use Hoa\Ruler\Ruler;
use Hoa\Ruler\Context;

/*
	规则引擎验证条件
*/
class Validata
{

	/*
		* 条件验证
		* rule 条件语句
		* context 组装的数据
		* return boolean
	*/
	public static function validata($params)
	{

		$ruler = new Ruler();
		$rule  = $params['rule'];
		
		$context = new Context();
		foreach($params['context'] as $key=>$val)
		{
			$context[$key] = $val;
		}
		return $ruler->assert($rule, $context);
	}


	## 有倍数的 条件验证
	/*
		* 条件验证
		* rule 条件语句
		* context 组装的数据
		* return boolean
	*/	
	public static function validataMultiple($params)
	{
		$ruler = new Ruler();
		$rule  = $params['rule'];
		
		$context = new Context();
		foreach($params['context'] as $key=>$val)
		{
			$context[$key] = $val;
		}

		$ruler->getDefaultAsserter()->setOperator('multiple', function ($tiems) {

			var_dump($tiems);
		 	return true;
		});

		return $ruler->assert($rule, $context);
	}





}